package org.shoukaiseki.web.module.elenium.controller;

import org.shoukaiseki.web.config.exec.SeleniumActuator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.annotation.SessionScope;

import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;

/**
 * org.shoukaiseki.web.module.elenium.controller.EleniumController <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  2019-01-20 18:20:17<br>
 * ブログ http://shoukaiseki.blog.163.com/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
@SessionScope
@Controller
@RequestMapping("module/elenium")
public class EleniumController {

    String id;

    @Value("${bear.login.username}")
    private String username;

    @Value("${bear.login.password}")
    private String password;

    SeleniumActuator seleniumActuator=new SeleniumActuator();

    private String prefix = "module/elenium";

    @RequestMapping()
    public String index(ModelMap mmap){
        if(id==null){
            id= UUID.randomUUID().toString();
        }
        mmap.put("id",id);
        return prefix+"/job";
    }

    @RequestMapping("reset")
    @ResponseBody
    public Integer reset(){
        seleniumActuator.login(username,password);
        return 0;
    }

    @RequestMapping("search")
    @ResponseBody
    public Object search(){
        Object search = seleniumActuator.search("868802049323827");

        return search;
    }

    @RequestMapping("test")
    @ResponseBody
    public Object test(@RequestParam Map<String,String> map){
        Object search = seleniumActuator.test(map.get("hwjs"));

        return search;
    }

    @RequestMapping("test2")
    @ResponseBody
    public Object test2(){
        Object search = seleniumActuator.test2();

        return search;
    }
}
